const { projectPhaseModel } = require('./projectPhase');

// 初始化项目阶段示例数据 - 独立单表
const initProjectPhaseData = async () => {
    try {
        // 检查是否已有数据
        const count = await projectPhaseModel.countDocuments();
        if (count > 0) {
            console.log('项目阶段数据已存在，跳过初始化');
            return;
        }

        // 示例数据
        const sampleData = [
            {
                id: 1,
                status: '已完成',
                statusType: 'blue',
                progress: '100%',
                phase: '需求分析阶段',
                phaseType: '自研',
                leader: '李某',
                startTime: new Date('2024-01-01'),
                endTime: new Date('2024-01-15'),
                period: 15,
                hour: 120,
                realEndTime: new Date('2024-01-14'),
                realPeriod: 14,
                realHour: 110,
                bonusType: '固定金额',
                bonusAmount: 5000,
                calculateWorkTime: true,
                isConfirmPhase: true,
                isPaymentPhase: true,
                deliverFiles: ['需求文档', '功能列表', '原型图'],
                files: '需求文档；功能列表；原型图',
                remark: '需求分析已完成，客户已确认',
                creator: '系统管理员',
                createTime: new Date('2024-01-01'),
                updateTime: new Date('2024-01-14'),
                days: 0
            },
            {
                id: 2,
                status: '进行中',
                statusType: 'orange',
                progress: '60%',
                phase: '设计阶段',
                phaseType: '自研',
                leader: '王某',
                startTime: new Date('2024-01-16'),
                endTime: new Date('2024-02-15'),
                period: 30,
                hour: 240,
                realEndTime: null,
                realPeriod: null,
                realHour: null,
                bonusType: '固定金额',
                bonusAmount: 8000,
                calculateWorkTime: true,
                isConfirmPhase: true,
                isPaymentPhase: false,
                deliverFiles: ['UI设计稿', '交互设计', '技术方案'],
                files: 'UI设计稿；交互设计；技术方案',
                remark: '设计阶段进行中，预计提前完成',
                creator: '系统管理员',
                createTime: new Date('2024-01-16'),
                updateTime: new Date('2024-01-16'),
                days: 0
            },
            {
                id: 3,
                status: '未开始',
                statusType: 'gray',
                progress: '0%',
                phase: '开发阶段',
                phaseType: '分包',
                leader: '张某',
                startTime: new Date('2024-02-16'),
                endTime: new Date('2024-04-15'),
                period: 60,
                hour: 480,
                realEndTime: null,
                realPeriod: null,
                realHour: null,
                bonusType: '固定金额',
                bonusAmount: 15000,
                calculateWorkTime: true,
                isConfirmPhase: false,
                isPaymentPhase: true,
                deliverFiles: ['源代码', '测试报告', '部署文档'],
                files: '源代码；测试报告；部署文档',
                remark: '等待设计阶段完成后开始',
                creator: '系统管理员',
                createTime: new Date('2024-01-20'),
                updateTime: new Date('2024-01-20'),
                days: 0
            },
            {
                id: 4,
                status: '已暂停',
                statusType: 'red',
                progress: '30%',
                phase: '测试阶段',
                phaseType: '自研',
                leader: '赵某',
                startTime: new Date('2024-04-16'),
                endTime: new Date('2024-05-15'),
                period: 30,
                hour: 240,
                realEndTime: null,
                realPeriod: null,
                realHour: null,
                bonusType: '固定金额',
                bonusAmount: 6000,
                calculateWorkTime: true,
                isConfirmPhase: true,
                isPaymentPhase: false,
                deliverFiles: ['测试用例', '测试报告', '用户手册'],
                files: '测试用例；测试报告；用户手册',
                remark: '因客户需求变更暂停',
                creator: '系统管理员',
                createTime: new Date('2024-01-25'),
                updateTime: new Date('2024-01-25'),
                days: 0
            }
        ];

        // 插入数据
        await projectPhaseModel.insertMany(sampleData);
        console.log('项目阶段示例数据初始化成功');
    } catch (error) {
        console.error('项目阶段数据初始化失败:', error);
    }
};

module.exports = {
    initProjectPhaseData
}; 